package com.example.tokendemo.common.domain;


import com.example.tokendemo.common.constant.HttpStatus;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Objects;

public class AjaxResult extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;

    private static final String CODE_TAG = "code";

    private static final String MSG_TAG = "msg";

    private static final String DATA_TAG = "data";

    public AjaxResult(){

    }

    public AjaxResult(int code, String msg){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
    }

    public AjaxResult(int code, String msg, Object data){
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        if (Objects.isNull(data)){
            super.put(DATA_TAG, data);
        }
    }

    public static AjaxResult success(String msg, Object data){return new AjaxResult(HttpStatus.SUCCESS, msg, data);}


    public static AjaxResult success(String msg){return AjaxResult.success(msg,null);}


    public static AjaxResult success(){return AjaxResult.success("操作成功");}
}
